#include <iostream>
#include <stdio.h>

using namespace std;

int main() {
    int a,b,n;
    cin >> a >> b;
    n = max(a,b) % min(a,b);
    while(n != 0){
        if(max(a,b) == a){
            a = n;
        }
        else{
            b = n;
        }
        n = max(a,b) % min(a,b);
        // cout << ' ' << n;
    }
    cout << min(a,b);
    return 0;
}